import time
from concurrent.futures import ThreadPoolExecutor, ALL_COMPLETED, FIRST_COMPLETED, wait

TPE = ThreadPoolExecutor(max_workers=5)


def excutor(t):
    if type(t)==str:
        print(' %s finished' % t)
    else:
        time.sleep(t)
        print('this is :%s finished' % t)


urls = [1, 2, 3, 4, 5]
names = ['mark', 'tolle', 'rose', 'linus', 'newman', 'blues']
running = [TPE.submit(excutor, u) for u in names]
# 等待直到指定条件成立，可阻塞主线程
wait(running, return_when=ALL_COMPLETED)
print('all finished')
